 

package com.zdkj.subway.rca.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zdkj.common.core.util.R;
import com.zdkj.common.log.annotation.SysLog;

import com.zdkj.subway.rca.entity.SwCkClearOtherAccount;
import com.zdkj.subway.rca.service.SwCkClearOtherAccountService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;


/**
 * 清分及划账-清分及划账记录-应急纸票与退款清分
 *
 * @author stw
 * @date 2021-01-01 18:02:59
 */
@RestController
@AllArgsConstructor
@RequestMapping("/swckclearotheraccount" )
@Api(value = "swckclearotheraccount", tags = "清分及划账-清分及划账记录-应急纸票与退款清分")
public class SwCkClearOtherAccountController {

    private final SwCkClearOtherAccountService swCkClearOtherAccountService;

    /**
     * 分页查询
     * @param page 分页对象
     * @return
     */
    @ApiOperation(value = "分页查询,startDate 格式：yyyy-MM-dd, endDate 格式： yyyy-MM-dd", notes = "分页查询")
    @GetMapping("/page" )
    public R getSwCkClearOtherAccountPage(Page page,String lineCode, String startDate, String endDate) {
        SwCkClearOtherAccount swCkClearOtherAccount = new SwCkClearOtherAccount();
        swCkClearOtherAccount.setLineCode(lineCode);
        if(StringUtils.isNotEmpty(startDate)) {
            swCkClearOtherAccount.setBeginTime(LocalDate.parse(startDate, DateTimeFormatter.ofPattern("yyyy-MM-dd")));
        }
        if(StringUtils.isNotEmpty(endDate)) {
            swCkClearOtherAccount.setEndTime(LocalDate.parse(endDate, DateTimeFormatter.ofPattern("yyyy-MM-dd")));
        }

        return R.ok(swCkClearOtherAccountService.page(page, Wrappers.query(swCkClearOtherAccount)));
    }

    /**
     * 清分及划账-清分及划账记录-应急纸票与退款清分-系统自动清分
     * @return R
     */
    @ApiOperation(value = "清分及划账-清分及划账记录-应急纸票与退款清分-系统自动清分，点击“系统自动清分”按钮弹出窗口选择时间段(二者必须选)", notes = "清分及划账-清分及划账记录-系统自动清分，点击“系统自动清分”按钮弹出窗口选择时间段(二者必须选)")
    @SysLog("清分及划账-清分及划账记录-应急纸票与退款清分-系统自动清分" )
    @GetMapping({"/autoClean"})
    @PreAuthorize("@pms.hasPermission('sw_ck_clear_other_account_autoClean')" )
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "startDate", value = "开始日期", dataTypeClass = String.class, required = true),
                    @ApiImplicitParam(name = "endDate", value = "结束日期", dataTypeClass = String.class, required = true)
            }
    )
    public R autoClean(String startDate, String endDate) {
        try {
            if (StringUtils.isEmpty(startDate) || StringUtils.isEmpty(endDate)){
                return R.failed();
            }

            return R.ok(swCkClearOtherAccountService.generateSwCkClearOtherAccount(startDate, endDate));
        } catch (Exception e) {
            e.printStackTrace();
            return R.failed();
        }

    }

    /**
     * 清分及划账-应急纸票与退款清分-重新清分
     * @return R
     */
    @ApiOperation(value = "清分及划账-清分及划账记录-应急纸票与退款清分-重新清分，必须选择左边复选框，可多选", notes = "清分及划账-清分及划账记录-应急纸票与退款清分-重新清分，必须选择左边复选框，可多选")
    @SysLog("清分及划账-清分及划账记录-应急纸票与退款清分-重新清分" )
    @GetMapping({"/reClean"})
    @PreAuthorize("@pms.hasPermission('sw_ck_clear_other_account_reClean')" )
    public R reClean(@RequestParam(value = "ids") List<Long> ids) {
        try {
            if (ids == null || ids.isEmpty()){
                return R.failed();
            }

            return R.ok(swCkClearOtherAccountService.reGenerateSwCkClearOtherAccount(ids));
        } catch (Exception e) {
            e.printStackTrace();
            return R.failed();
        }

    }

}
